package com.blame.springblog.common.utils;


import com.blame.springblog.pojo.dataobject.BlogInfo;
import com.blame.springblog.pojo.dataobject.UserInfo;
import com.blame.springblog.pojo.request.UpdateBlogRequest;
import com.blame.springblog.pojo.response.BlogInfoResponse;
import com.blame.springblog.pojo.response.UserInfoResponse;
import org.springframework.beans.BeanUtils;

public class BeanTranUtils {
    public static BlogInfoResponse tran(BlogInfo blogInfo){
        if(blogInfo==null){
            return new BlogInfoResponse();//如果没有这篇博客文章，返回一个空对象
        }
        BlogInfoResponse response=new BlogInfoResponse();  //创建一个新的对象
        BeanUtils.copyProperties(blogInfo,response);
        return response;
    }

    public static UserInfoResponse tran(UserInfo userInfo){
        if(userInfo==null){
            return new UserInfoResponse();
        }
        UserInfoResponse response=new UserInfoResponse();  //创建一个新的对象
        BeanUtils.copyProperties(userInfo,response);
        return response;
    }


    public static BlogInfo tran(UpdateBlogRequest updateBlogRequest){
        if(updateBlogRequest==null){
            return new BlogInfo();
        }
        BlogInfo blogInfo=new BlogInfo();  //创建一个新的对象
        BeanUtils.copyProperties(updateBlogRequest,blogInfo);
        return blogInfo;
    }

}
